package org.cloud.im.core.protocol;

import org.cloud.im.core.ImChannelContext;
import org.cloud.im.core.ImPacket;
import org.cloud.im.core.exception.ImException;

import java.nio.ByteBuffer;

/**
 * @Author: w.weidong.lin@abite.com
 * @Description: 协议校验接口
 * @Date: create in 2021/10/19 14:14
 */
public interface IProtocol {
    /**
     * 协议名称
     *
     * @return 如:http、ws、tcp等
     */
    String name();

    /**
     * 根据buffer判断是否属于指定协议
     *
     * @param buffer
     * @param imChannelContext
     * @return
     * @throws ImException
     */
    boolean isProtocol(ByteBuffer buffer, ImChannelContext imChannelContext) throws ImException;

    /**
     * 根据imPacket判断是否属于指定协议
     *
     * @param imPacket
     * @param imChannelContext
     * @return
     * @throws ImException
     */
    boolean isProtocol(ImPacket imPacket, ImChannelContext imChannelContext) throws ImException;
}
